home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 2 / CU Amiga Magazine's Super CD-ROM 02 (1996)(EMAP Images)(GB)[!][issue 1996-04].iso / magazine / amiga_e / jrh-rkrm-partone / exec_library / interrupts / vertb.e < prev   
Text File  |  1995-04-05  |  2KB  |  64 lines

  1. -> vertb.e - Vertical blank interrupt server example.
  2.  
  3. -> E-Note: we need eCodeSoftInt() in order to execute E code as an interrupt
  4. ->         (this wouldn't be needed if we just used Assembly, see below)
  5. MODULE 'other/ecode',
  6.        'dos/dos',
  7.        'exec/interrupts',
  8.        'exec/memory',
  9.        'exec/nodes',
  10.        'hardware/intbits'
  11.  
  12. ENUM ERR_NONE, ERR_ECODE
  13.  
  14. PROC main() HANDLE
  15.   DEF vbint:PTR TO is, counter=0, endcount
  16.  
  17.   -> Allocate memory for interrupt node.
  18.   vbint:=NewM(SIZEOF is, MEMF_PUBLIC OR MEMF_CLEAR)
  19.   vbint.ln.type:=NT_INTERRUPT  -> Initialise the node.
  20.   vbint.ln.pri:=-60
  21.   vbint.ln.name:='VertB-Example'
  22.   vbint.data:={counter}
  23.   vbint.code:=eCodeIntServer({vertBServer})
  24.   IF vbint.code=NIL THEN Raise(ERR_ECODE)
  25.  
  26.   AddIntServer(INTB_VERTB, vbint)  -> Kick this interrupt server into life.
  27.  
  28.   WriteF('VBlank server will increment a counter every frame.\n')
  29.   WriteF('counter started at zero, CTRL-C to remove server\n')
  30.  
  31.   Wait(SIGBREAKF_CTRL_C)
  32.   endcount:=counter
  33.   WriteF('\d vertical blanks occurred\nRemoving server\n', endcount)
  34.  
  35.   RemIntServer(INTB_VERTB, vbint)
  36.  
  37. EXCEPT DO
  38.   -> E-Note: not really necessary...
  39.   IF vbint THEN Dispose(vbint)
  40.   SELECT exception
  41.   CASE ERR_ECODE;  WriteF('Error: Ran out of memory in eCodeIntServer()\n')
  42.   CASE "MEM";      WriteF('Error: Ran out of memory\n')
  43.   ENDSELECT
  44. ENDPROC
  45.  
  46. -> Entered with:       A0 == scratch (execpt for highest pri vertb server)
  47. ->  D0 == scratch      A1 == is_Data
  48. ->  D1 == scratch      A5 == vector to interrupt code (scratch)
  49. ->                     A6 == scratch
  50. ->
  51. -> E-Note: we could use this Assembly, but we'll show how to use a PROC instead
  52. ->         (so we needed eCodeIntServer() above)
  53. ->
  54. -> vertBServer:
  55. ->   ADDI.L #1, (A1)  -> Increments counter is_Data points to
  56. ->   MOVEQ.L #0, D0   -> Set Z flag to continue to process other vb-servers
  57. ->   RTS              -> Return to exec
  58.  
  59. -> E-Note: we get vbint.data as an argument, and the PROC result should be
  60. ->         zero to continue with other servers in this chain (the default),
  61. ->         or non-zero (e.g., RETURN TRUE) to skip them
  62. PROC vertBServer(data:PTR TO LONG)
  63.   data[]:=data[]+1
  64. ENDPROC